package helpers;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.hibernate.repackage.cglib.transform.impl.AddDelegateTransformer;

public class ObjectCounter {
private List <ObjectCount> objectCountList;
	public ObjectCounter()
	{
		objectCountList=new ArrayList<ObjectCount>();
	}
	
	public void add(Object object)
	{
		ObjectCount existingObjectCount=findObject(object);
		if(existingObjectCount==null)
		{
			ObjectCount newOc=new ObjectCount();
			newOc.setCount(1);
			newOc.setObject(object);
			objectCountList.add(newOc);
		}
		else
		{
			existingObjectCount.setCount(existingObjectCount.getCount()+1);
		}
		 Collections.sort(objectCountList);
	}
	
	
	public ObjectCount findObject(Object object)
	{
            for (ObjectCount objCnt : objectCountList) {
				if (objCnt.getObject().equals(object))
				{
					return(objCnt);
				}
			}
            return null;
	}

	public Object getObjectbyDecendingOrder(int Position)
	{System.out.println("objectCountList.size()="+objectCountList.size());
		return objectCountList.get(objectCountList.size()-1).getObject();
	}

}
